<template>
	<view class="wrap">
		<view class="search-box">
			<u-search placeholder="搜索" shape="square" v-model="searchData.phone" @search="onSearch" :showAction="false"/>
			<view class="custom-btn" @click="$u.route('/pages/shop/Staff/edit', {type: '1'})">新增员工</view>
		</view>
		<view class="my-list pl-0 pr-0">
			<u-list v-if="dataList.length > 0" :height="swiperHeight" @scrolltolower="scrolltolower">
				<u-list-item v-for="(item, index) in dataList" :key="item.id">						  
					<view class="item flex align-center justify-between" @click="$u.route('/pages/shop/Staff/details', { id: item.id })">
						<view class="w-100">
							<view class="flex align-center">
								<u-icon :name="item.sex===1?'man':item.sex===2?'woman':''" :color="item.sex===1?'#3c9cff':item.sex===2?'#f56c6c':''" size="14" />
								<text class="ml-6">{{item.nickName}}</text>
								<text class="ml-6 fsize-26 line-cyan">({{item.storeName}})</text>
							</view>
							<view class="mt-10 w-100">
								<view class="subtitleinline w-45">
									<text class="text-gray">可结算提成:</text>
									<text class="fsize-22 ml-10">￥</text>
									<text class="fsize-28">{{item.canTocashAmount}}</text>
								</view>
								<view class="subtitleinline">
									<text class="text-gray">累计业绩:</text>
									<text class="fsize-22 ml-10">￥</text>
									<text class="fsize-28">{{item.allOrderAmount}}</text>
								</view>
							</view>
						</view>
						<view class="vertical-center shrink0" @click.stop>
							<uni-icons 
								@click="$u.route('/pages/shop/Staff/edit', {id: item.id, type: '2'})"
								custom-prefix="iconfont"  
								type="icon-bianji" 
								color="#5dc5ff" 
								size="28"
							/>
							<uni-icons
								@click="$u.route('/pages/shop/Staff/setKPI', {id: item.id})"
								custom-prefix="iconfont"  
								type="icon-yuedukaohe" 
								color="#e54d42" 
								size="28"
							/>
						</view>
					</view>
				</u-list-item>
			</u-list>
		</view>
		<!-- 无数据时默认显示 -->
		<view class="emptybox" v-if="dataList.length === 0">
			<u-empty icon-size="100" text="暂无数据" mode="data"></u-empty>
		</view>
	</view>
</template>

<script>	
	import listHeightMixin from '@/common/computedAltitude.js'
	export default {
		mixins:[listHeightMixin],
		data() {
			return {
				dataList: [],
				searchData: {
					phone:'',
					page: 1,
					limit: 20
				},
				loadmore:{
					status: 'loadmore',
					iconType: 'flower',
					loadText: {
						loadmore: '轻轻上拉',
						loading: '努力加载中',
						nomore: '实在没有了'
					},
				},
			}
		},
		
		onLoad() {
			this.getPageList()
			uni.$on('upStaffList', obj=>{
				this.onSearch()
			})
		},
		onUnload() {
			uni.$off('upStaffList')
		},
		methods: {
			onSearch() {
				this.dataList = []
				this.searchData.page = 1
				this.getPageList()
			},
			getPageList(){
				this.$reqPost('GetStaffPageList',this.searchData).then(res=>{
					this.dataList = [...this.dataList, ...res.data]
					if (res.count > this.dataList.length) {
						this.loadmore.status = 'loadmore'
						this.searchData.page++
					} else {
						// 数据已加载完毕
						this.loadmore.status = 'nomore'
					}
				})
			},
			scrolltolower() {
				if (this.loadmore.status === 'loadmore') {
					this.getPageList()
				}
			}
		}

	}
</script>

<style lang="scss" scoped>
.btn-plus {
	position: absolute;
	bottom: 50rpx;
	right: 50rpx;
	z-index: 1;
	opacity: 0.6;
}
.btn-plus:hover {
	opacity: 1;
}
.subtitleinline{ 
	display: inline-block; 
	padding-right: 10px; 
	font-size: 14px;
}
.vertical-center{ 
	display: flex;
	justify-content: center;
	align-items: center;
}
</style>
